package it.cst.util;

import it.cst.entity.Role;
import it.cst.entity.service.RoleService;


import java.util.List;

public class Roles {
	private static Roles uniqInstance;
	public static String DEFENSE_ROLE_NAME = "difesa";
	public static String ATTACK_ROLE_NAME = "attacco";
	
	private Roles() {}
	
	private List<Role> roles;

	  public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

	public static synchronized Roles getInstance(RoleService roleService) {
	    if (uniqInstance == null) {
	      uniqInstance = new Roles();
	      uniqInstance.roles = roleService.listRole();
	    }
	    return uniqInstance;
	  }
	
	
	public Role getRole(String roleName){
		for(Role role : roles){
			if(role.getRole().equalsIgnoreCase(roleName)){
				return role;
			}
		}
		return null;
	}
	
	public Role getRole(Integer roleId){
		for(Role role : roles){
			if(role.getId().compareTo(roleId) == 0){
				return role;
			}
		}
		return null;
	}
}
